<template>
  <div class="page shippingAddress-body">
    <custom title="收货地址" />
    <div class="shippingAddress-header"></div>
    <div class="shippingAddress-main">
      <van-radio-group v-model="checked">
        <div v-for="(item, index) in items" :key="item" class="shippingAddress-item">
          <div class="item-main" @click="onBack()">
            <div class="item-left">
              <div class="item-header">
                <div v-if="item.isDefault" class="item-icon"></div>
                <div class="item-title">{{ item.adress }}</div>
              </div>
              <div class="item-addressdetail">{{ item.addressdetail }}</div>
              <div class="item-user">{{ item.name }} {{ item.tel }}</div>
            </div>
            <div class="item-right">
              <van-icon name="arrow" size="23" color="#B2B2B2" />
            </div>
          </div>

          <div class="item-footer" @click="checkboxClick(item, index)">
            <div class="item-footer-left">
              <van-radio
                :name="index"
                checked-color="#FE8813"
                icon-size="17px"
                data-item="item"
              >默认地址</van-radio>
            </div>
            <div class="item-footer-right" @click="showPopup">删除</div>
          </div>
        </div>
      </van-radio-group>
    </div>
    <van-popup v-model:show="show" overlay-class="popup-overlay" class="popup-style">
      <div class="popup-title">确定要删除改地址吗？</div>
      <div class="popup-button">
        <van-button class="popup-button-left" @click="closePopup">取消</van-button>
        <van-button style="color:#FFF;">删除</van-button>
      </div>
    </van-popup>
    <div class="shippingAddress-footer">
      <van-button @click="onGoAddress()">新增收货地址</van-button>
    </div>
  </div>
</template>

<script>
import custom from '@/components/custom.vue'
import { ref } from 'vue'
export default {
  components: {
    custom
  },
  setup() {
    const show = ref(false)
    const showPopup = () => {
      show.value = true
    }
    const closePopup = () => {
      show.value = false
    }
    return {
      show,
      showPopup,
      closePopup
    }
  },
  data() {
    return {
      items: [
        {
          adress: '广西壮族自治区  柳州市 城中区 ',
          addressdetail: '西一巷66号606室',
          name: '余少先生',
          tel: '188****9831'
        },
        {
          adress: '广西壮族自治区  柳州市 城中区 ',
          addressdetail: '西一巷66号606室',
          name: '余少先生',
          tel: '188****9831'
        },
        {
          adress: '广西壮族自治区  柳州市 城中区 ',
          addressdetail: '西一巷66号606室',
          name: '余少先生',
          tel: '188****9831'
        },
        {
          adress: '广西壮族自治区  柳州市 城中区 ',
          addressdetail: '西一巷66号606室',
          name: '余少先生',
          tel: '188****9831'
        }
      ],

      custom: {
        isSelect: false,
        isKeyboard: false,
        value: ''
      },
      checked: 1
    }
  },
  created() {},
  methods: {
    checkboxClick(item, index) {
      console.log('item', item)
      console.log('index', index)
      this.checked = index
    },
    onGoAddress() {
      this.$router.push('/addNewAddress')
    },
    onBack() {
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped lang="less">
.shippingAddress-body {
  background-color: #f2f2f2;
  ::v-deep .van-popup {
    width: 500px;
    height: 240px;
    background: #ffffff;
    border-radius: 10px;
  }
  .popup-title {
    height: 130px;
    line-height: 130px;
    text-align: center;
    font-size: 28px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #000000;
  }
  .popup-button {
    display: flex;
    justify-content: space-between;
    margin: 0 50px;
    ::v-deep .van-button {
      height: 0;
    }
    ::v-deep .van-button__content {
      width: 180px;
      height: 70px;
      background: linear-gradient(90deg, #ef3814 0%, #ff8d13 100%);
      border-radius: 10px;
    }
    ::v-deep .van-button--normal {
      padding: 0;
    }
    .popup-button-left {
      ::v-deep .van-button__content {
        background: #dddddd;
      }
    }
  }
}
.shippingAddress-header {
  height: 19px;
  background-color: #f2f2f2;
}
.shippingAddress-footer {
  text-align: center;
  margin-top: 130px;
  position: relative;
  // bottom: 20px;
  left: 0;
  right: 0;
  ::v-deep .van-button__content {
    width: 630px;
    height: 80px;
    background: linear-gradient(90deg, #ef3814 0%, #ff8d13 100%);
    // opacity: 0.3;
    border-radius: 10px;
    font-size: 28px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #ffffff;
    line-height: 50px;
    text-align: center;
    line-height: 80px;
    margin: 0 auto;
    // margin-top: 130px;
  }
  ::v-deep .van-button--normal {
    padding: 0;
  }
}
.shippingAddress-item {
  font-size: 24px;
  font-family: PingFang SC;
  font-weight: 400;
  color: #676767;
  height: 240px;
  background-color: #fff;
  border-top: 1px solid #f2f2f2;
  .item-footer {
    display: flex;
    justify-content: space-between;
    margin: 0 40px;
    height: 79px;
    border-top: 1px solid #f2f2f2;
    // justify-items: center;
    .item-footer-right,
    .item-footer-right {
      line-height: 80px;
    }
    .item-footer-left {
      display: flex;
      align-items: center;
    }
  }
  .item-main {
    height: 160px;
    margin: 0 40px;
    display: flex;
    justify-content: space-between;
    .item-header {
      margin-top: 31px;
      display: flex;
      height: 38px;
      align-items: center;
      .item-icon {
        width: 64px;
        height: 28px;
        background-image: url(../../assets/shipingAdress/default.png);
        background-repeat: no-repeat;
        background-size: cover;
        margin-right: 11px;
      }
      .item-title {
        line-height: 28px;
      }
    }
    .item-right {
      display: flex;
      align-items: center;
    }
    .item-addressdetail {
      font-size: 26px;
      font-weight: 500;
      color: #000000;
      height: 38px;
      line-height: 38px;
    }
    .item-user {
      height: 36px;
      line-height: 36px;
    }
  }
}
</style>
